/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package introsemp;

import java.awt.Font;
import java.awt.event.*;
import javax.swing.*;

/**
 *
 * @author Marit
 */
public class Login {
    public static void main (String args[]) {
        Login login = new Login();
        
    }
    MainFrame main;
    
    /************ Username == 0 with any password will bring you to the Faculty Member menu
                  Username == 1 with any password will bring you to the System Admin menu
                  Username == 3 with any password will bring you to the Asst Principal for Academics menu ***********/
    public Login(){
        final JFrame dbox = new JFrame();
        
        final JTextField usernameField = new JTextField();
        final JPasswordField passwordField = new JPasswordField();
        JButton signin = new JButton("Sign in");
        
        

        dbox.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        dbox.setSize(470,380);
        dbox.setLayout(null);
        signin.setFocusPainted(false);
        
        
        try {
            UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
        } catch (Exception evt) {
            evt.printStackTrace();
        }

        signin.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if (passwordField.getPassword().length==0 || usernameField.getText().isEmpty()) {
                    
                    JOptionPane.showMessageDialog(dbox,"Incorrect username/password", "Login", JOptionPane.ERROR_MESSAGE);
                }
                else {
                    if (usernameField.getText().contains("0")) {
                        main = new MainFrame();
                        main.faculty();
                        dbox.dispose();
                    } else if (usernameField.getText().contains("1")) {
                        main = new MainFrame();
                        main.admin();
                        dbox.dispose();
                    } else if (usernameField.getText().contains("3")) {
                        main = new MainFrame();
                        main.asstPrincipal();
                        dbox.dispose();
                    } else 
                        JOptionPane.showMessageDialog(dbox,"Incorrect username/password", "Login", JOptionPane.ERROR_MESSAGE);
                    
                }
            }
        });


        usernameField.setSize(330, 30);
        passwordField.setSize(330, 30);
        usernameField.setLocation(55, 130);
        passwordField.setLocation(55, 215);
        usernameField.setVisible(true);
        passwordField.setVisible(true);

        signin.setSize(80, 35);
        signin.setLocation(170, 265);
        signin.setVisible(true);
        signin.setFont(new Font("Segoe UI", Font.PLAIN, 15));


        JLabel bg = new JLabel(new ImageIcon("Images\\login.png"));
        bg.setSize(453, 339); 
        bg.setVisible(true);
        
        dbox.add(signin);
        dbox.add(usernameField);
        dbox.add(passwordField);
        dbox.add(bg);
        
        dbox.setVisible(true);
    }
}
